home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / mathematica.359 < prev    next >
Text File  |  1992-02-06  |  1KB  |  59 lines

  1. Mathematica communications functions
  2.  
  3. Q: How do I communicate with Mathametica through installed programs?
  4.  
  5. A: This application requires mathlink.[hc], given in QA360, to run correctly.
  6.  
  7. #include "mathlink.h"
  8. #include <string.h>
  9.  
  10. main()
  11. {
  12.      int  BitAnd(), CheckSum();
  13.      char c1[40];
  14. /*
  15. **  notify Mathematica that we are going to link code into it
  16. */
  17.      printf("i got here \n");
  18.      MathInit();
  19.      
  20. /*
  21. **  install our new procedures
  22. */
  23.      strcpy(c1,"x_Integer");
  24.      strcat(c1,"y_Integer");
  25.      MathInstall(BitAnd,"BitAnd","int","x_Integer,y_Integer","int, int");
  26.      MathInstall(CheckSum,"CheckSum","int","x_String \0","char *");
  27. /*
  28. **  give usage messages for them
  29. */
  30.      MathExec("BitAnd::usage = \"BitAnd[x,y] computes the bitwise logical AND of the (machine-length) integers x and y.\"");
  31.      MathExec("CheckSum::usage = \"CheckSum[x] computes a checksum for the string x.\"");
  32.  
  33. /*
  34. **  relinquish control to Mathematica, and wait to be called
  35. */
  36.      MathStart();
  37. }
  38.  
  39. int BitAnd(x,y)
  40. {
  41.      return(x&y);
  42. }
  43.  
  44. int CheckSum(x)
  45.      char *x;
  46. {
  47.      register int n,i;
  48.      n = 0;
  49.      while ( i = *x++ ) n = (n+i) % 256;
  50.      return(n);
  51. }
  52.  
  53. QA359
  54.  
  55. Valid for 1.0 
  56. Not checked yet for 2.0 
  57.  
  58.  
  59.